package com.ml.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 配置交换机和队列的绑定关系
 * 1、声明交换机
 * 2、声明队列
 * 3、将队列绑定到交换机上
 * @Author : zzy
 * @CreateTime : 2021-04-08
 **/
@Configuration
public class DeadRabbitConfig {

    public static final String DEAD_TTL_EXCHANGE = "dead_ttl_exchange";
    public static final String DEAD_TTL_ROUTING_KEY = "dead";
    //交换机
    @Bean
    public DirectExchange DeadDirectExchange() {
        return new DirectExchange(DEAD_TTL_EXCHANGE, true, false);
    }

    //队列
    @Bean
    public Queue DeadDirectQueue() {
        return new Queue("dead.ttl.queue", true);
    }

    //绑定  将队列和交换机绑定
    @Bean
    public Binding bindingDeadEmail(){
        return BindingBuilder.bind(DeadDirectQueue()).to(DeadDirectExchange()).with(DEAD_TTL_ROUTING_KEY);
    }

}
